package tags.templates;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import main.PMF;

import DBClasses.GameType;
import DBClasses.NewsLetter;
import DBClasses.User;

public class CategoriesTag extends TagSupport
{
	@SuppressWarnings("unchecked")
	public int doStartTag() throws JspException
	{
		String result = "";
		PersistenceManager manager = PMF.get().getPersistenceManager();
		List<GameType> cats=null;
		try
		{
			cats = (List<GameType>) manager.newQuery(
					"select from " + GameType.class.getName()).execute();
		} catch (Exception ex)
		{
			result = "<div style=\"margin:20px\">Категорий пока нет...</div>";
		}
		if (cats != null && cats.size() > 0)
		{
			for (GameType gt : cats)
			{
				result += 
					"<a class=\"log_reg_btn top_text_stl right_cat_style\" href=\"/categories.jsp?id="+gt.getId()+"\">"+gt.getName()+"</a>";					
			}
		} else
		{
			result = "<div style=\"margin:20px\">Категорий пока нет...</div>";
		}
		try
		{
			pageContext.getOut().flush();
			pageContext.getOut().print(result);
		} catch (Exception ex)
		{
			throw new JspException(ex.getMessage());
		}
		manager.close();
		return SKIP_BODY;
	}

	public void release()
	{
	}
}
